<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   家居商家广告状态控制器($小牛New $2014.07.28)*/

!defined('Q_PATH') && exit;

class JiajucompanyadController extends AController{

	public function init__(){
		$this->_arrNotMethod=array(
			'save_previewstatus',
			'save_preview',
			'view_preview',
			'foreverdelete',
			'foreverdelete_deep',
			'input_change_ajax',
			'input_change_unique',
			'forbid',
			'closeitem',
			'openitem',
			'resume',
			'clear_recycle',
			'save_sort',
			'insert',
			'add',
			'edit',
			'update'
		);
		
		parent::init__();
	}
	
	public function index($sName=null,$bDisplay=true){
		// VIP到期时间
		$arrVip=Model::F_('jiajucompanyvip','jiajucompany_id=?',$GLOBALS['_company_']['jiajucompany_id'])
			->setColumns('jiajucompanyvip_starttime,jiajucompanyvip_endtime')
			->getOne();
		
		// 广告列表
		$arrAds=Model::F_('ad')->where(array('jiajucompany_id'=>$GLOBALS['_company_']['jiajucompany_id'],'ad_status'=>1))
			->setColumns('ad_id,create_dateline,ad_name,ad_type,ad_setting,ad_starttime,ad_endtime,ad_ispreset')
			->getAll();

		$this->assign('arrVip',$arrVip);
		$this->assign('arrAds',$arrAds);
		$this->display();
	}

	public function preview($arrAd){
		$sHtml=<<<WINDSFORCE
<div class="adminpreview_box" id="adminpreviewbox-{$arrAd['ad_id']}" style="max-width:500px;">
	<div class="adminpreview_title">广告预览&nbsp;&nbsp;&nbsp;
		<a title="点击关闭" href="javascript:void(0);" onclick="closePreviewad('{$arrAd['ad_id']}');" title="关闭">x</a>
	</div>
	<div class="module_content">{content}</div>
</div>
WINDSFORCE;
		$sCode='';

		$arrAd=Core_Extend::getAdlink($arrAd);
		switch($arrAd['type']){
			case 'text':
				$sCode="<a href=\"{$arrAd['link']}\" target=\"_blank\" style=\"{$arrAd['style']}\">{$arrAd['title']}</a>";
				break;
			case 'image':
				$sCode="<a href=\"{$arrAd['link']}\" target=\"_blank\" title=\"{$arrAd['title']}\"><img src=\"{$arrAd['logo']}\" alt=\"{$arrAd['title']}\" style=\"max-width:500px;\"/></a>";
				break;
			case 'code':
				$sCode=htmlspecialchars($arrAd['html']);
			case 'flash':
				$sCode="<object style=\"padding-left:0px;padding-top: 5px;\" type='application/x-shockwave-flash' data='{$arrAd['file']}' width='400' height='200'>
					<param name='wmode' value='transparent' />
					<param name='movie' value='{$arrAd['file']}' />
				</object>";
				break;
		}

		echo str_replace('{content}',$sCode,$sHtml);
	}

}
